home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
telecomm
/
sticpsrc.lzh
/
SOURCE.ARC
/
PC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-21
|
14KB
|
634 lines
/* OS- and machine-dependent stuff for IBM-PC running MS-DOS */
#include <stdio.h>
#include <ctype.h>
#if (defined(MSC) || defined(__TURBOC__))
# include <process.h>
# include <signal.h>
# ifdef MSC
# include <malloc.h>
void (*getvect())();
# endif
#else
# ifdef RAWCON
# include <sgtty.h>
# endif
#endif
#include "global.h"
#include "config.h"
#include "mbuf.h"
#include "internet.h"
#include "iface.h"
#include "cmdparse.h"
#include "timer.h"
#include "environ.h"
/* Interface list header */
struct interface *ifaces;
#if (!defined(MSC) && !defined(__TURBOC__))
/* Aztec memory allocation control */
int _STKLOW = 0; /* Stack above heap */
int _STKSIZ = 4096/16; /* 4K stack -- overridden in grabcore */
int _HEAPSIZ = 4096/16; /* Isn't really used */
int _STKRED = 4096; /* Stack red zone in bytes -- this really matters */
#endif
char ttbuf[BUFSIZ];
#ifdef SERVERS
extern FILE *logfp; /* log file pointer */
extern char logname[]; /* log file name */
#endif
#ifdef TRACE
extern FILE *trfp; /* trace file pointer */
extern char trname[]; /* trace file name */
#endif
static unsigned watchhw; /* watchdog hardware reset value */
static unsigned watchport; /* watchdog output port number */
#if (defined(MSC) || defined(__TURBOC__))
/* critical error handler stuff - will fail system calls all the time */
void (*orgcritvect)(void);
extern void crit_hdl(void);
void crit_remove (void)
{
setvect(0x24,orgcritvect);
}
#endif
/* Called at startup time to set up console I/O, memory heap */
ioinit()
{
#if (!defined(MSC) && !defined(__TURBOC__))
# ifdef RAWCON
struct sgttyb ttybuf;
# endif
#endif
/* Save these file table entries for something more useful */
/* PE1CHL: this seems to cause problems so let's skip it for awhile */
#ifdef CLOSEDEVS
# ifdef stdaux
fclose(stdaux);
# endif
# ifdef stdprn
fclose(stdprn);
# endif
# ifdef stdprt
fclose(stdprt);
# endif
#endif
#if (!defined(MSC))
/* Interrupts use a special stack deep in data space.
* Calls to sbrk() (invoked by malloc when it needs more memory
* from the system) at interrupt time will fail because sbrk()
* will think that the stack has overwritten the heap. So
* grab all the memory we can now for the heap so that malloc
* won't have to call sbrk and alloc_mbuf() won't fail unnecessarily
* at interrupt time.
*/
grabcore();
#endif
setbuf(stdout,ttbuf);
#if (defined(MSC) || defined(__TURBOC__))
signal(SIGINT,SIG_IGN); /* don't like killing NET */
#else
# ifdef RAWCON
/* Put display in raw mode. Note that this breaks tab expansion,
* so you need to run NANSI.SYS or equivalent.
*/
ioctl(1,TIOCGETP,&ttybuf);
ttybuf.sg_flags = RAW;
ioctl(1,TIOCSETP,&ttybuf);
# endif
#endif
#if (defined(MSC) || defined(__TURBOC__))
orgcritvect = getvect(0x24);
setvect(0x24,crit_hdl);
atexit(crit_remove);
#endif
}
/* Called just before exiting to restore console state */
iostop()
{
#if (!defined(MSC) && !defined(__TURBOC__))
# ifdef RAWCON
struct sgttyb ttybuf;
# endif
#endif
#if (!defined(MSC) && !defined(__TURBOC__))
# ifdef RAWCON
ioctl(1,TIOCGETP,&ttybuf);
ttybuf.sg_flags &= ~RAW;
ioctl(1,TIOCSETP,&ttybuf);
# endif
#endif
while(ifaces != NULLIF){
/* first flush the interface's buffers */
while(ifaces->recv != NULLFP && (*ifaces->recv)(ifaces))
;
if(ifaces->stop != NULLFP)
(*ifaces->stop)(ifaces);
ifaces = ifaces->next;
}
}
/* Print or Set the date and time */
dodate(argc,argv)
int argc;
char *argv[];
{
long tloc;
register char *p;
#ifdef MSC
struct dosdate_t dosdate;
struct dostime_t dostime;
#endif
#ifdef __TURBOC__
struct date dosdate;
struct time dostime;
#endif
if (argc < 2) {
time(&tloc);
printf("%s",ctime(&tloc));
return 0;
}
#if (defined(MSC) || defined(__TURBOC__))
p = argv[1];
if (strlen(p) != 10 && strlen(p) != 12)
return -1;
while (*p)
if (!isdigit(*p++))
return -1;
# ifdef MSC
_dos_getdate(&dosdate); /* read the year */
p = argv[1];
dosdate.month = 10 * p[0] + p[1] - 11 * '0';
dosdate.day = 10 * p[2] + p[3] - 11 * '0';
dostime.hour = 10 * p[4] + p[5] - 11 * '0';
dostime.minute = 10 * p[6] + p[7] - 11 * '0';
dostime.second = 10 * p[8] + p[9] - 11 * '0';
if (p[10]) {
if ((dosdate.year = 10 * p[10] + p[11] - 11 * '0' + 1900) < 1980)
dosdate.year += 100;
}
dostime.hsecond = 0;
if (_dos_settime(&dostime) || _dos_setdate(&dosdate))
return -1;
# endif
# ifdef __TURBOC__
getdate(&dosdate); /* read the year */
p = argv[1];
dosdate.da_mon = 10 * p[0] + p[1] - 11 * '0';
dosdate.da_day = 10 * p[2] + p[3] - 11 * '0';
dostime.ti_hour = 10 * p[4] + p[5] - 11 * '0';
dostime.ti_min = 10 * p[6] + p[7] - 11 * '0';
dostime.ti_sec = 10 * p[8] + p[9] - 11 * '0';
if (p[10]) {
if ((dosdate.da_year = 10 * p[10] + p[11] - 11 * '0' + 1900) < 1980)
dosdate.da_year += 100;
}
dostime.ti_hund = 0;
settime(&dostime);
setdate(&dosdate);
# endif
#else
printf("Date/Time setting not supported in this version!\n");
#endif
return 0;
}
/* Spawn subshell */
doshell(argc,argv)
int argc;
char *argv[];
{
char *command,**envp;
int ret;
#ifdef MSDOS
unsigned short envseg;
#endif
#if (!defined(MSC) && !defined(__TURBOC__))
# ifdef RAWCON
struct sgttyb ttybuf,ttysav;
ioctl(1,TIOCGETP,&ttysav);
ioctl(1,TIOCGETP,&ttybuf);
ttybuf.sg_flags &= ~RAW;
ioctl(1,TIOCSETP,&ttybuf);
# endif
#endif
if((command = getenv("COMSPEC")) == NULLCHAR)
command = "/COMMAND.COM";
#ifdef SERVERS
if (logfp != NULLFILE) /* logging to file? */
fclose(logfp);
#endif
#ifdef TRACE
if (trfp != stdout) /* trace to file? */
fclose(trfp); /* close it during shell exec */
#endif
envp = make_env(); /* create env, starts on PARA bound */
#if (defined(MSC) || defined(__TURBOC__))
ret = spawnve(P_WAIT,command,&argv[0],envp);
#else
if (envp != NULLCHRP) /* could the env be allocated? */
envseg = getds() + (((unsigned) envp[0]) >> 4); /* get segment addr of env */
else
envseg = 0; /* no space, pass our own env */
ret = fexecve(command,&argv[0],envseg);
# ifdef RAWCON
ioctl(1,TIOCSETP,&ttysav);
# endif
#endif
free_env(); /* free the envp and temp env */
#ifdef SERVERS
if (logfp != NULLFILE) /* re-open logfile if it was open */
logfp = fopen(logname,"a+");
#endif
#ifdef TRACE
if (trfp != stdout) /* re-open tracefile if not stdout */
if ((trfp = fopen(trname,"a+")) == NULLFILE)
trfp = stdout;
#endif
if (ret != 0)
return -1;
#if (defined(MSC) || defined(__TURBOC__))
return 0;
#else
return wait();
#endif
}
#if (!defined(MSC) && !defined(__TURBOC__))
/* the following piece of code was taken from the Aztec 4.10 runtime */
/* source for fexecv() and slightly adapted to pass the environment */
/* to the executed program. */
/* Copyright (C) 1983, 1984 by Manx Software Systems */
fexecve(path, argv, env)
char *path, **argv;
unsigned short env;
{
register char *cp, *xp;
int i;
char buffer[130];
char fcb1[16], fcb2[16];
cp = buffer+1;
i = 1;
fcbinit(".", fcb1); /* initialize fcb's, in case no args */
fcbinit(".", fcb2);
if (*argv) {
++argv; /* skip arg0, used for unix (tm) compatibility */
while ((xp = *argv++) != '\0') {
if (i == 1)
fcbinit(xp, fcb1);
else if (i == 2)
fcbinit(xp, fcb2);
*cp++ = ' ';
while (*xp) {
if (cp >= buffer+127)
goto done;
*cp++ = *xp++;
}
++i;
}
}
done:
buffer[0] = cp - (buffer+1);
*cp = '\r'; /* add CR to make some dos commands happy */
return fexec(path, env, buffer, fcb1, fcb2);
}
#endif
/* checks the time then ticks and updates ISS */
static short clockstart = 0;
static int32 clkval = 0;
void
check_time()
{
int32 iss();
int32 ntime;
int maxticks = SEC2TICK(15); /* upper limit on delayed ticks */
char i_state;
#if (defined(MSC) || defined(__TURBOC__))
# define peekw(off,seg) (*((unsigned far*) (((long) (seg